@@ -92,34 +92,34 @@ FormatterFunc createFormat() throws Exception {
92
92
93
93
Class <?> optionCls = classLoader .loadClass ("scala.Option" );
94
94
Class <?> configCls = classLoader .loadClass ("org.scalafmt.config.Config" );
95
+ Class <?> scalafmtCls = classLoader .loadClass ("org.scalafmt.Scalafmt" );
95
96
96
97
Object either ;
97
98
98
99
try {
99
- // scalafmt >= v0.7.0-RC1
100
- Method fromHocon = configCls .getMethod ("fromHoconString" , String .class , optionCls );
101
- Object fromHoconEmptyPath = configCls .getMethod ("fromHoconString$default$2" ).invoke (null );
100
+ // scalafmt >= 1.6.0
101
+ Method parseHoconConfig = scalafmtCls .getMethod ("parseHoconConfig" , String .class );
102
102
103
103
String configStr = new String (Files .readAllBytes (file .toPath ()), StandardCharsets .UTF_8 );
104
104
105
- Object configured = fromHocon .invoke (null , configStr , fromHoconEmptyPath );
105
+ Object configured = parseHoconConfig .invoke (null , configStr );
106
106
either = invokeNoArg (configured , "toEither" );
107
107
} catch (NoSuchMethodException e ) {
108
- // In case of a NoSuchMethodException try old configuration API
109
- // scalafmt <= v0.6.8
110
- Method fromHocon = configCls .getMethod ("fromHocon" , String .class , optionCls );
111
- Object fromHoconEmptyPath = configCls .getMethod ("fromHocon$default$2" ).invoke (null );
108
+ // scalafmt >= v0.7.0-RC1 && scalafmt < 1.6.0
109
+ Method fromHocon = configCls .getMethod ("fromHoconString" , String .class , optionCls );
110
+ Object fromHoconEmptyPath = configCls .getMethod ("fromHoconString$default$2" ).invoke (null );
112
111
113
112
String configStr = new String (Files .readAllBytes (file .toPath ()), StandardCharsets .UTF_8 );
114
- either = fromHocon .invoke (null , configStr , fromHoconEmptyPath );
113
+
114
+ Object configured = fromHocon .invoke (null , configStr , fromHoconEmptyPath );
115
+ either = invokeNoArg (configured , "toEither" );
115
116
}
116
117
117
118
config = invokeNoArg (invokeNoArg (either , "right" ), "get" );
118
119
}
119
120
return input -> {
120
121
Object resultInsideFormatted = formatMethod .invoke (null , input , config , emptyRange );
121
- String result = (String ) formattedGet .invoke (resultInsideFormatted );
122
- return result ;
122
+ return (String ) formattedGet .invoke (resultInsideFormatted );
123
123
};
124
124
}
125
125
}
0 commit comments